﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.Threading;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using DecisionFramework.Instrument;

namespace Tests.DecisionFramework.Instrument
{
	/// <summary>
	/// Provides test cases for Instrumentation.
	/// </summary>
	/// <remarks>  
	/// Author: Greg Cowin
	/// </remarks> 
	[TestClass]
	public class InstrumentationTest
	{
		private Instrumentation Instrumentation = new Instrumentation("InstrumentationTest");

		[TestMethod]
		public void Instrumentation_TakeMeasurement_AppropriateAmountOfTime()
		{
            // arrange

            // act
			Instrumentation.Measure("TestMeasure", () =>
				{
					Thread.Sleep(200);
				});

            // assert
			Console.WriteLine(Instrumentation.ToString());
			long avgTime = Instrumentation.MetricsForOperation("TestMeasure").ShortestTimeInTicks;
			long avgTimeInMilliseconds = avgTime / 10000;

			Assert.IsTrue(avgTimeInMilliseconds >= 200 && avgTimeInMilliseconds < 220);
		}
	}
}
